<?php

namespace App\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Traits\HasPermissions;

class Roles extends BaseModel
{
    protected $connection = 'mysql';
    use HasPermissions;
    protected $table = 'roles';
    
    protected $fillable = ['name'];
    
    protected $guard_name = 'web';
    
    protected $attributes = [
        'guard_name' => 'web'
    ];
    private $fields = ['id','name','created_at','desc'];
    
    public function getList(Request $request){
        $limit = $request->input('limit',10);
        $page = $request->input('page',1);
        $query = new Roles();
        // todo 搜索
        return $query->paginate($limit,$this->fields,'page',$page);
    }

    public function getAllRole(){
        return DB::table($this->table)->get();
    }
    
    public function getRoles(){
        return $this->get(collect($this->fields)->only(['id','name']));
    }
}
